<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>watch option</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
  <h1>watch option</h1>
  <hr>
  <div id="app">
    <p>Today temperature:{{temperature}}</p>
    <p>cloth:{{cloth}}</p>
    <p><button @click="rise">增加温度</button><button @click="reduce">降低温度</button></p>
  </div>
  <script type="text/javascript">
  var app = new Vue({
    el:'#app',
    data:{
      temperature:14,
      cloth:'夹克长裙'
    },
    methods:{
      reduce:function(){
        this.temperature -= 5;
      },
      rise:function(){
        this.temperature += 5;
      }
    },
    // watch:{
    //   temperature:function(newVal,oldVal){
    //     if(newVal >= 29){
    //       this.cloth = '超短裙';
    //     }
    //     else{
    //       this.cloth = '夹克长裙';
    //     }
    //   }
    // }
  })
  app.$watch('temperature',function(newVal,oldVal){
        if(newVal >= 29){
          this.cloth = '超短裙';
        }
        else{
          this.cloth = '夹克长裙';
        }
      })
  </script>
</body>
</html>